<?php

// Error reporting
error_reporting(E_ALL);
ini_set('display_errors', 1);

// logged in user
App::$Current->User = session('user');

// user page user
App::$Current->Page->User = get_profile_user();

App::$Current->Language = session('language');

// set language
if(get('language') != '')
{
	language(get('language'));
	$Path = $_SERVER['REQUEST_URI'];
	if(strpos($Path, '?') !== false)
		$Path = stristr($Path, '?', true);
	header('Location: ' . $Path);
	exit;
}

function get_profile_user()
{
	$Path = $_SERVER['REQUEST_URI'];
	if(strpos($Path, '?') !== false)
		$Path = stristr($Path, '?', true);
	$uriparts = explode('/', $Path);
	if(count($uriparts) > 1 && $uriparts[1] == 'user')
		return $uriparts[count($uriparts) - 1];
	return null;
}